// FqlDataSourceDesigner.cs
// Facebook/FrameworkWeb/Design/Web
// Copyright (c) 2007, Nikhil Kothari. All Rights Reserved.
//

using System;
using System.Collections;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Diagnostics;
using System.Web.UI.Design;
using System.Web.UI.Design.WebControls;
using Facebook.Web;

namespace Facebook.Design.Web {

    /// <summary>
    /// The designer associated with the <see cref="FqlDataSource"/> control.
    /// </summary>
    public class FqlDataSourceDesigner : DataSourceDesigner {

        /// <summary>
        /// Gets the designer data source view associated with the particular view name.
        /// </summary>
        /// <param name="viewName">The name of the view.</param>
        /// <returns>The associated designer data source view.</returns>
        public override DesignerDataSourceView GetView(string viewName) {
            if ((String.IsNullOrEmpty(viewName) == false) &&
                (String.Compare(viewName, FqlDataSource.FqlViewName, StringComparison.OrdinalIgnoreCase) != 0)) {
                throw new ArgumentOutOfRangeException("viewName");
            }

            return new FqlResultsDesignerDataSourceView(this);
        }

        /// <summary>
        /// Gets the names of the available designer data source views.
        /// </summary>
        /// <returns>The list of designer data source view names.</returns>
        public override string[] GetViewNames() {
            return new string[] { FqlDataSource.FqlViewName };
        }

        /// <summary>
        /// Initalizes an instance of a FqlDataSourceDesigner with its associated
        /// component.
        /// </summary>
        /// <param name="component">The associated component.</param>
        public override void Initialize(IComponent component) {
            if (!(component is FqlDataSource)) {
                throw new ArgumentOutOfRangeException("component");
            }

            base.Initialize(component);
        }


        private sealed class FqlResultsDesignerDataSourceView : DesignerDataSourceView {

            private FqlDataSourceDesigner _owner;

            public FqlResultsDesignerDataSourceView(FqlDataSourceDesigner owner)
                : base(owner, FqlDataSource.FqlViewName) {
                _owner = owner;
            }
        }
    }
}
